/**
 * @Author:周邱艳
 * @Date:2020/6/30
 * @Description:这是持仓列表页
 */
import React,{Component} from "react";
import {Card, Icon, NavBar, WhiteSpace} from "antd-mobile";
import axios from "axios";
import {getCookieId} from "../../Login/Component_Login/GetCookie";

export default class HoldingCard extends Component{
    constructor(props) {
        super(props);
        this.state={
            positionDetail:[]//json表名
        }
        this.loadData = this.loadData.bind(this)
        this.handleLeftClick = this.handleLeftClick.bind(this)
    }
    handleLeftClick(event){
        localStorage.setItem("tabs",2)
        this.props.history.push('/terran/my')
    }
    loadData(){
        axios({
            method:"GET",
            url:"http://39.101.141.248:9527/wealthAccount/showTotalPosition",
            params:{userId:getCookieId()}//this.props.userId,this.props.tradeId
        }).then(res=>{
            var totalEarning=res.data.positionDetail.totalEarning
            var totalMoney=res.data.positionDetail.totalMoney
            var yesterdayEarning=res.data.positionDetail.yesterdayEarning
            this.setState({
                positionDetail:this.state.positionDetail.concat(res.data.positionDetail),
                totalEarning:totalEarning,
                totalMoney:totalMoney,
                yesterdayEarning:yesterdayEarning
            })
        }).catch(error =>{
            console.log(error)
        })
    }
    componentDidMount() {
        this.loadData()
    }
    render() {
        return (
            <div>
                {/*页面顶部*/}
                <div style={{width:"100%",height:"16rem",backgroundColor:"#cda66e"}}>
                    <p style={{fontSize:"1.5rem",color:"white",paddingTop:"1.5rem",marginLeft:"1rem"}}>持仓金额（元）</p>
                    <p style={{fontSize:"3.2rem",color:"white",marginTop:"0.6rem",marginLeft:"1rem",marginBottom:"1rem"}}>{this.state.totalMoney}</p>
                    <div style={{width:"49%",height:"6rem",float:"left"}}>
                        <p style={{fontSize:"1.5rem",color:"white",marginLeft:"1rem"}}>昨日收益（元）</p>
                        <p style={{fontSize:"15px",color:"white",marginTop:"0.5rem",marginLeft:"1rem"}}>{this.state.yesterdayEarning}</p>
                    </div>
                    <div style={{width:"49%",height:"6rem",float:"left"}}>
                        <p style={{fontSize:"1.5rem",color:"white",marginLeft:"1rem"}}>累计收益（元）</p>
                        <p style={{fontSize:"15px",color:"white",marginTop:"0.5rem",marginLeft:"1rem"}}>{this.state.totalEarning}</p>
                    </div>

                </div>
                <WhiteSpace/>
            </div>
        );
    }
}
